package vshevchuk;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;

public class ds_xml extends IDS 
{
	{
		name = "XML";
	}


	@Override
	public void Save(ArrayList<Base> p) throws Exception 
	{
		try
		{
			BufferedWriter out = new BufferedWriter(new FileWriter("data.xml"));
		    out.write("<?xml version=\"1.0\"?>\r\n<class>\r\n");
		    
			for (int i=0; i<p.size(); i++)	
			{
				out.write(p.get(i).toXML());
			}
			out.write("</class>");
			out.close();
		}
		catch(FileNotFoundException e)
		{
        	
    	}

	}

	@Override
	public ArrayList<Base> Load() throws Exception 
	{
		String str;
		ArrayList<Base> p=null;
		int i=0;
		
		try
		{
			BufferedReader in = new BufferedReader(new FileReader("data.xml"));
			while((str = in.readLine()) != null)
			{
				if ((i>1) && (i<22)) 
				{
					p.add(Base.CreatClass(str,"XML"));
				}
				i++;
			}	
			in.close();
		}
    	catch(FileNotFoundException e)
    	{
        	
    	}
		return p;
	}

}
